<html><head><title>AllocateMemory</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="4">AllocateMemory()</font></b></p>
<p><b>Syntax</b></p><blockquote>
*MemoryID = <font color="#006666"><b>AllocateMemory</b></font>(Size [, Flags])</blockquote>

<b>Description</b><br><blockquote>

Allocates a contiguous memory area with the specified size in bytes. 
The new memory area will be cleared and filled with zeros. 

</blockquote><p><b>Parameters</b></p><blockquote>
<style type="text/css">
table.parameters { border-spacing: 0px; border-style: none; border-collapse: collapse; }
table.parameters td { border-width: 1px; padding: 6px; border-style: solid; border-color: gray; vertical-align: top; font-family:Arial; font-size:10pt; }
</style>
<table width="90%" class="parameters">
<tr><td width="10%"><i>Size</i></td>
<td width="90%"> 
The size in bytes for the new memory area. 

</td></tr>
<tr><td><i>Flags (optional)</i></td>
<td> 
It can be one of the following values: 
<pre><font face="Courier New, Courier, mono"size="2">  <font color="#924B72">#PB_Memory_NoClear</font>: don't fill the new memory area with zeros. It can help to have faster allocation if the
                      allocated memory is used immediately.
</font></pre>

</td></tr>
</table>
</blockquote><p><b>Return value</b></p><blockquote>

Returns the address of the allocated memory, or zero if the memory cannot be allocated. 

</blockquote><p><b>Remarks</b></p><blockquote>

<a href="freememory.html">FreeMemory()</a> can be used to return the allocated memory back to the system. 
<a href="reallocatememory.html">ReAllocateMemory()</a> can be used to change the size of the allocated area. 
All the allocated memory areas are automatically freed when the programs ends. 
<br>
<br>
If the program crashes at this command, it is usually a result of a memory corruption at 
an earlier time in the program by writing at an area outside of the allocated memory area. 
Such an error can be narrowed down to the real cause using the 
<a href="../reference/ide_debugtools.html">purifier</a> debugger tool. 

</blockquote><p><b>Example</b></p><blockquote>

<pre><font face="Courier New, Courier, mono"size="2">  *MemoryID =<font color="#006666"> AllocateMemory</font>(5000)
  <b><font color="#006666">If</font></b> *MemoryID
    <b><font color="#006666">Debug</font></b> "Starting address of the 5000 Byte memory area:"
    <b><font color="#006666">Debug</font></b> *MemoryID
<font color="#006666">    PokeS</font>(*MemoryID, "Store this string in the memory area")
<font color="#006666">    FreeMemory</font>(*MemoryID)  <font color="#006666">; will also be done automatically at the end of program</font>
  <b><font color="#006666">Else</font></b>
    <b><font color="#006666">Debug</font></b> "Couldn't allocate the requested memory!"
  <b><font color="#006666">EndIf</font></b>
</font></pre>

</blockquote><p><b>See Also</b></p><blockquote>

<a href="reallocatememory.html">ReAllocateMemory()</a>, <a href="freememory.html">FreeMemory()</a>, <a href="memorysize.html">MemorySize()</a> 

</Blockquote><p><b>Supported OS </b><Blockquote>All</Blockquote></p><center><a href=index.html>Memory Index</a> - <a href=allocatestructure.html>AllocateStructure()</a> ->

</body></html>